package com.banciyuan.bcywebview.biz.main.mainpage.timeline;

import android.content.Context;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.banciyuan.bcywebview.api.TimelineApi;
import com.banciyuan.bcywebview.base.factory.TimelineFactory;
import com.banciyuan.bcywebview.base.helper.data.UserDataHelper;
import com.banciyuan.bcywebview.utils.http.HttpUtils;
import com.banciyuan.bcywebview.utils.http.StringRequestParam;
import com.banciyuan.bcywebview.utils.http.VolleyQueue;

import com.banciyuan.bcywebview.utils.http.BcyPair;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import de.greenrobot.daoexample.model.Timeline;

/**
 * Created by squall on 2016/3/30.
 */
public class BanTimeLineHelper {

    private BanTimeLineInter banTimeLineInter;
    private RequestQueue requestQueue;
    private Context context;

    public BanTimeLineHelper(BanTimeLineInter banTimeLineInter, Context context) {
        this.banTimeLineInter = banTimeLineInter;
        this.context = context;
        this.requestQueue = VolleyQueue.getRquest(context);
    }

    public void doBan(Timeline timeline) {
        String url = HttpUtils.BASE_URL + TimelineApi.getDoBan();

        Response.Listener<String> onSucc = new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                banTimeLineInter.succ(response);
            }
        };

        Response.ErrorListener onError = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                banTimeLineInter.fail();
            }
        };

        List<BcyPair> pairs = new ArrayList<BcyPair>();
        pairs.add(new BcyPair(HttpUtils.TOKEN, UserDataHelper.getInstance(context).getToken()));
        pairs.add(new BcyPair(HttpUtils.TYPE, TimelineFactory.getTimeLineTypeName(timeline)));
        pairs.add(new BcyPair(HttpUtils.ID, TimelineFactory.getTimeLineid(timeline)));
        Map<String, String> map = HttpUtils.getData(pairs);
        StringRequestParam requestParam = new StringRequestParam(Request.Method.POST, url, map, onSucc, onError);
        requestQueue.add(requestParam);

    }

    public void doBanSpot(Timeline timeline) {
        String url = HttpUtils.BASE_URL + TimelineApi.getBanSpot();

        Response.Listener<String> onSucc = new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                banTimeLineInter.succ(response);
            }
        };

        Response.ErrorListener onError = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                banTimeLineInter.fail();
            }
        };

        List<BcyPair> pairs = new ArrayList<BcyPair>();
        pairs.add(new BcyPair(HttpUtils.TOKEN, UserDataHelper.getInstance(context).getToken()));
        pairs.add(new BcyPair(HttpUtils.ES_ID, TimelineFactory.getTimeLineid(timeline)));
        Map<String, String> map = HttpUtils.getData(pairs);
        StringRequestParam requestParam = new StringRequestParam(Request.Method.POST, url, map, onSucc, onError);
        requestQueue.add(requestParam);
    }

    public void doBanWork(final String wid) {
        String url = HttpUtils.BASE_URL + TimelineApi.getDoBan();

        Response.Listener<String> onSucc = new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                banTimeLineInter.succ(response);
            }
        };

        Response.ErrorListener onError = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                banTimeLineInter.fail();
            }
        };


        List<BcyPair> pairs = new ArrayList<>();
        pairs.add(new BcyPair(HttpUtils.TOKEN, UserDataHelper.getInstance(context).getToken()));
        pairs.add(new BcyPair(HttpUtils.TYPE, "work"));
        pairs.add(new BcyPair(HttpUtils.ID, wid));
        Map<String, String> map = HttpUtils.getData(pairs);
        StringRequestParam requestParam = new StringRequestParam(Request.Method.POST, url, map, onSucc, onError);
        requestQueue.add(requestParam);
    }
}
